<?php
    session_start();
    $userName=$_SESSION['userName'];
?>  
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <link href="http://fonts.googleapis.com/css?family=Oswald" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen, projection">
    <script type="text/javascript" src="jquery-1.4.2.min.js">
   
    
    
    </script>

  </head>

  <!-- ============== START OF BODY ================ -->
  <body>
    <div id="wrapper">
    <div id="header">
        <div id="logo">
            <h1><a href="index.php">Trail Finder</a></h1>
            <p>A Guide to Getting Outside</p>
        </div>
        <div id="menu">
        <ul>
            <li>
                <form method='link' action='logout.php'>
                    <input type='submit' value='Logout'>
                </form>
            </li>
        </ul>
        </div>
    </div>

    <div id="page">
        <div id="accountcontent">
        <h2>Account Info</h2>
    <?php
    // run initializer to set $username, $password, $database
    include("dbinfo.inc.php");
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    if(!$userName)
    {
    	echo "<p>Please login</p><br/>";

	}
	else
	{
        $accountquery="SELECT * FROM Account WHERE userName like '$userName'";
        $accountresult=mysql_query($accountquery);
        $fname = mysql_result($accountresult,0,"firstName");
        $lname = mysql_result($accountresult,0,"lastName");
        $city = mysql_result($accountresult,0,"city");
        $state = mysql_result($accountresult,0,"state");
        $dob = mysql_result($accountresult,0,"DOB");
        $gender = mysql_result($accountresult,0,"sex");
        $bio = mysql_result($accountresult,0,"bio");
        $photo = mysql_result($accountresult,0,"photo");
        $userID = mysql_result($accountresult,0,"ID");
        echo "<div id='accountinfo'>";
        if($photo != '')
	    {
	    	list($width, $height, $type, $attr) = getimagesize("userphotos/".$photo);
		    if($width > 300 && $height > 300)
		    {
		    	if($width > $height)
		    	{
		    		echo "<img width='300' src='userphotos/" . $photo . "'/><br><br>";
				}
				else
				{
					echo "<img height='300' src='userphotos/" . $photo . "'/><br><br>";
				}
			}
			elseif($width > 300 && height < 300)
			{
				echo "<img width='300' src='userphotos/" . $photo . "'/><br><br>";
			}
			elseif($height > 300 && $width < 300)
			{
				echo "<img height='200' src='userphotos/" . $photo . "'/><br><br>";
			}
			else
			{
		        echo "<img src='userphotos/" . $photo . "'/><br><br>";
	        }
	    }
        echo "<table cellpadding='5'>";
          echo "<tr>";
            echo "<td><font color='#6D6D6D'>  Name </font></td>";
            echo "<td>".$fname . " " .$lname ."</td>";
          echo "</tr>";
          if($city != '' && $state != ''){
          echo "<tr>";
            echo "<td><font color='#6D6D6D'>  From </font></td>";
            echo "<td>" . $city . ", " . $state . "</td>";
          echo "</tr>";}
          if($dob != '0000-00-00'){
          echo "<tr>";
            echo "<td><font color='#6D6D6D'>  Birthday </font></td>";
            echo "<td>" . $dob ."</td>";
          echo "</tr>";}
          if($gender != ''){
          echo "<tr>";
            echo "<td><font color='#6D6D6D'>  Sex </font></td>";
            if($gender == 'm')
            {
        	    echo "<td>Male</td>";
            }
	        if($gender == 'f')
	        {
		        echo "<td>Female</td>";
	        }
          echo "</tr>";}
          
        echo "</table>";
       
	    echo "<form action='uploadFile.php' method='post'";
	    echo "enctype='multipart/form-data'>";
	    if($photo == '')
	    {
            echo "<label for='file'>Upload Profile Picture: </label>";	
	    }
	    else
	    {
	        echo "<label for='file'>Change Profile Picture: </label>";
	    }
	    echo "<input type='file' name='file' id='file'><br>";
	    echo "<input type='submit' name='submit' value='Submit'>";
	    echo "</form>";
		echo "</div>";
		
		echo "<div id='accountbio'>";
		echo "<h3 style='padding-bottom:5px;'>About Me</h3>";
            if($bio == '')
            {  
                echo $fname . " has not entered their biography.";
            }
            else{
	        echo "<p>" . $bio . "</p>";
	    }
	$savedquery = "SELECT * FROM Saved WHERE userID like '$userID' ORDER by headID";
	$savedresult = mysql_query($savedquery);
	$numsaved=mysql_numrows($savedresult);
        if ($numsaved > 0)
        {    
            $i=0;
            echo "<h3 style='padding-bottom:5px;'>My Saved Trails</h3>";
            echo "<table>";
            echo "<th align='left'>Trailhead</th>";
            echo "<th align='left'>Trail</th>"; 
            while ($i < $numsaved) {
                $trailID=mysql_result($savedresult,$i,"trailID");
                $headID=mysql_result($savedresult,$i,"headID");
                $trailquery = "SELECT * FROM Trail WHERE ID like '$trailID'";
                $trailresult = mysql_query($trailquery);
                $trailname = mysql_result($trailresult,0,"name");
                $trailheadquery= "SELECT * FROM TrailHead WHERE ID like '$headID'";
                $trailheadresult = mysql_query($trailheadquery);
                $trailheadname = mysql_result($trailheadresult,0,"name");
                echo "<tr>";
                echo "<td>" . $trailheadname . "</td>";
                echo "<td>" . $trailname . "</td>";
                echo "</tr>";
               // echo $trailheadname . ", " . $trailname . "<br>";
                $i = $i +1;
	        }        
            echo "</table>";
	    }
		
    }
    echo "</div>";
	mysql_close();
?>
    </div>
  
    </div>
  
  </body>

